package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.User;
import com.itheima.health.vo.UserVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface UserMapper extends BaseMapper<User> {

    //根据人员id删除  中间表  数据
    @Delete("delete from t_user_role where user_id = #{uid}")
    void deleteRidByUid(@Param("uid") Integer uid);

    //根据人员id在 中间表 中循环录入角色id信息
    @Insert("INSERT INTO t_user_role VALUES(#{uid},#{rid});")
    void addRidAndUid(@Param("uid") Integer uid, @Param("rid") Integer rid);


    //根据人员id查询人员信息  人员表
    @Select("SELECT birthday,username,password,telephone FROM t_user WHERE id=#{uid}")
    UserVO findByUid(@Param("uid") Integer uid);

    //根据人员id  查对应角色id 中间表
    @Select("SELECT role_id FROM t_user_role WHERE user_id=#{uid}")
    int[] findRids(@Param("uid") Integer uid);

//    @Delete("DELETE FROM t_user WHERE id=#{id}")
//    int deleteByUId(@Param("id") int id);
}
